package com.tre.jdevtemplateboot.common.authority;

import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author JDev
 */
@Component
public class GateKeeper {

    private List<String> permissionList;
    private String[] requiredPermissions;

    public GateKeeper scan(List<String> permissionList) {
        this.permissionList = permissionList;
        return this;
    }

    public GateKeeper find(String[] requiredPermissions) {
        this.requiredPermissions = requiredPermissions;
        return this;
    }

    public boolean any() {
        List<String> requiredPermissionsList = Arrays.asList(requiredPermissions);
        for (String requiredPermission : requiredPermissionsList) {
            if (permissionList == null || !permissionList.contains(requiredPermission)) {
                return false;
            }
        }
        return true;
    }
}
